package com.cskaoyan.bean;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * 泛型：泛型类、泛型接口、泛型方法
 * <T>
 *     隐性类型转换
 * @author stone
 * @date 2022/11/10 11:02
 */
public class Container {
    Map map = new HashMap();

    public void put(String key, Object value) {
        map.put(key, value);
    }


    public Object get(String key) {
        return map.get(key);
    }

    public <T> T get(Class<T> clazz) {
        Collection values = map.values();
        Iterator iterator = values.iterator();
        while (iterator.hasNext()) {
            T value = (T) iterator.next();
            boolean equal = value.getClass() == clazz;
            if (equal) {
                return (T)value;
            }
        }
        return null;
    }
}
